import React, { useEffect, useState } from 'react'
// 安装moment 后导入moment
import moment from 'moment'
export default function Timer() {
    let [nowTime, setNowTime] = useState(moment().format('YYYY-MM-DD HH:mm:ss'));

    useEffect(()=>{ // componentDidMount
        let timer = setInterval(()=>{
            console.log('111');
            setNowTime(moment().format('YYYY-MM-DD HH:mm:ss'));
        },1000)

        return ()=>{ // componentWillUnmout
            clearInterval(timer)
        }
    },[])
    return (
        <div>
            <h3>当前时间是： {nowTime}</h3>
        </div>
    )
}
